#include "motor.h"

extern TIM_HandleTypeDef htim1;

void Motor_Init(void) 
{
    
    // 启动PWM输出
    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
}

void Motor_SetSpeed(int8_t motor_id, int16_t speed) 
{    

    if (motor_id == 1) 
    {
        __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, speed);
    } 
    else if (motor_id == 2) 
    { 
        __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, speed);
    }
//	printf("Motor %d speed: %d\n", motor_id, speed);
}